﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections;
using PJ.Data;

namespace PJ.Business
{
    /// <summary>
    /// EntityFragmentService class
    /// </summary>
    /// <typeparam name="O">Object to serve type</typeparam>
    /// <typeparam name="OI">Object to serve interface type</typeparam>
    /// <typeparam name="OD">Inner data object type</typeparam>
    /// <typeparam name="ODP">Inner data object provider type</typeparam>
    public abstract class EntityFragmentService<OI, OD, ODP> : DataObjectService<OI, OD, ODP>, IEntityFragmentService<OI>
        where OI : class, IEntityFragment
        where OD : class, IEntityFragmentData
        where ODP : class, IEntityFragmentProvider<OD>
    {
        #region Constructor
        public EntityFragmentService(ODP dataService)
            : base(dataService)
        {
        }
        #endregion
        #region Public

        /// <summary>
        /// Gets the parent fragments list
        /// </summary>
        /// <param name="parentId">The parent Entity id</param>
        /// <returns>The collection of fragment object global ids</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="parent"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If no fragments exist for the parent.</exception>
        public IEnumerable<string> GetFragments(string parentId)
        {
            return DataService.GetFragments(parentId);
        }
        /// <summary>
        /// Gets the parent fragments list
        /// </summary>
        /// <param name="parentId">The parent Entity id</param>
        /// <returns>The collection of fragment object global ids if found else <see langref="null"/>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="parent"/> is <see langref="null"/> or empty.</exception>
        public IEnumerable<string> FindFragments(string parentId)
        {
            return DataService.FindFragments(parentId);
        }
        /// <summary>
        /// Gets the parent fragments list using cache first, if not in cache gest the fragment list from provider.
        /// </summary>
        /// <param name="parentId">The parent Entity id</param>
        /// <returns>The collection of fragment object global ids</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="parent"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If no fragments exist for the parent.</exception>
        public IEnumerable<string> CachedGetFragments(string parentId)
        {
            return DataService.CachedGetFragments(parentId);
        }
        /// <summary>
        /// Finds the parent fragments list using cache first, if not in cache gest the fragment list from provider.
        /// </summary>
        /// <param name="parentId">The parent Entity id</param>
        /// <returns>The collection of fragment object global ids if exist else <see langref="null"/>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="parent"/> is <see langref="null"/> or empty.</exception>
        public IEnumerable<string> CachedFindFragments(string parentId)
        {
            return DataService.CachedFindFragments(parentId);
        }

        #endregion

    }
}
